import sys

def getResult(n):
    mlist=[]
    res=0
    # 先求4的倍数
    for i in range(n):
        if i % 4 == 0:
            res+=1
        else:
            mlist.append(str(i))
    # 再算包含4的数字的个数

    for it in mlist:
        if '4' in it:
            res+=1
    return res

for line in sys.stdin:
    a = line.strip()
    print(getResult(int(a)))